//
//  DATabBar.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/9.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DATabBar.h"
#import "Utility.h"


@interface DATabBar ()

@end

@implementation DATabBar


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
  
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat barWidth = self.frame.size.width;
    CGFloat barHeight = self.frame.size.height;
    CGFloat buttonWidth = barWidth / 5;
    CGFloat buttonHeight = barHeight - 2;
    CGFloat buttonY = 1;
    NSInteger buttonIndex = 0;
    for (UIView *view in self.subviews) {
        NSString *viewClass = NSStringFromClass([view class]);
        if (![viewClass isEqualToString:@"UITabBarButton"]) {
            continue;
        }
        CGFloat buttonX = buttonIndex * buttonWidth;
        if (buttonIndex >= 2) { // 右边1个按钮
            buttonX += buttonWidth;
        }
        buttonIndex++;
        view.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
    }
    
    NSArray  *tabArray=self.subviews;
    for ( id obj  in tabArray) {
        if ([obj isKindOfClass:[UIButton class]]) {
            UIButton *button=(UIButton *) obj;
            [self bringSubviewToFront:button];
        }
    }
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    // Drawing code
//    [self setShadowImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 0.5)]];
//}

@end
